﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

using InfFront.InfoViews.Base;

namespace InfFront.InfoViews.WPF
{
    /// <summary>
    /// Interaction logic for ListViewFrame.xaml
    /// </summary>
    public partial class ListViewFrame : BaseListWithToolbarContentFrame
    {
        #region Private Variables
        #endregion

        public ListViewFrame()
        {
            InitializeComponent();
        }

        protected override void DoRebuild()
        {
            listView.ItemsSource = null;

            if (Source == null)
                return;

            listView.ItemsSource = Source.GetBindingSource();
        }

        protected override void DoRefresh()
        {
            listView.ItemsSource = Source.GetBindingSource();
        }

        private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IsRebuilding)
                return;

            InfoViewEntry entry = null;
            if (e.AddedItems.Count > 0)
                entry = Source.ExtractEntry(e.AddedItems[0]);
            Owner.UpdateWithNewCurrentEntry(entry);
            e.Handled = true;
        }
    }

    ///////////////////////////////////////////////////////////////////////////
    // view styles

    public class PlainView : ViewBase
    {

        public static readonly DependencyProperty ItemContainerStyleProperty =
            ItemsControl.ItemContainerStyleProperty.AddOwner(typeof(PlainView));

        public Style ItemContainerStyle
        {
            get { return (Style)GetValue(ItemContainerStyleProperty); }
            set { SetValue(ItemContainerStyleProperty, value); }
        }

        public static readonly DependencyProperty ItemTemplateProperty =
            ItemsControl.ItemTemplateProperty.AddOwner(typeof(PlainView));

        public DataTemplate ItemTemplate
        {
            get { return (DataTemplate)GetValue(ItemTemplateProperty); }
            set { SetValue(ItemTemplateProperty, value); }
        }

        public static readonly DependencyProperty ItemWidthProperty =
            WrapPanel.ItemWidthProperty.AddOwner(typeof(PlainView));

        public double ItemWidth
        {
            get { return (double)GetValue(ItemWidthProperty); }
            set { SetValue(ItemWidthProperty, value); }
        }


        public static readonly DependencyProperty ItemHeightProperty =
            WrapPanel.ItemHeightProperty.AddOwner(typeof(PlainView));

        public double ItemHeight
        {
            get { return (double)GetValue(ItemHeightProperty); }
            set { SetValue(ItemHeightProperty, value); }
        }
    }
}
